package com.duguo.dynamicmvc.view.resource;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.duguo.dynamicmvc.model.Model;
import com.duguo.dynamicmvc.view.View;
import com.duguo.dynamicmvc.view.resolver.ViewResolver;

public class ResourceControllerView implements View {
	
	private ViewResolver resourceViewResolver;
	
	public void render(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		View view=resourceViewResolver.resolve(request.getServletPath());
		if(view!=null)
			view.render(request, response, model);
		else
			response.sendError(HttpServletResponse.SC_NOT_FOUND);
	}

	public String getViewName() {
		return null;
	}

	public void setResourceViewResolver(ViewResolver resourceViewResolver) {
		this.resourceViewResolver = resourceViewResolver;
	}
}
